home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2018 January / PCgo 01-2018 CD-ROM Germany.iso / nw.pak / Unnamed File 005263.txt < prev    next >
Encoding:
Text File  |  2015-07-29  |  2.9 KB  |  77 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. // OS X and Linux only, Windows does not have a concept of workspaces
  22. var canSetVisibleOnAllWorkspaces = /(darwin|linux)/.test(require('os').platform());
  23.  
  24. exports.Window = {
  25.   get: function(other) {
  26.     // Return other window.
  27.     if (typeof other != 'undefined' && other.hasOwnProperty('nwDispatcher'))
  28.       return other.nwDispatcher.requireNwGui().Window.get();
  29.  
  30.     var id;
  31.     // See if this window context has requested Shell's id before.
  32.     if (typeof window.__nwWindowId == 'number')
  33.       id = window.__nwWindowId;
  34.     else // else see if the Shell has a corresponding js object.
  35.       id = nw.getShellIdForCurrentContext();
  36.  
  37.     // Return API's window object from id.
  38.     var ret;
  39.     if (id > 0) {
  40.       window.__nwWindowId = id;
  41.       ret = global.__nwWindowsStore[window.__nwWindowId];
  42.       if (!ret) {
  43.         ret = new global.Window(nw.getRoutingIDForCurrentContext(), true, id);
  44.       }
  45.       return ret;
  46.     }
  47.  
  48.     return new global.Window(nw.getRoutingIDForCurrentContext());
  49.   },
  50.   open: function(url, options) {
  51.     // Conver relative url to full url.
  52.     var protocol = url.match(/^[a-z]+:\/\//i);
  53.     if (protocol == null || protocol.length == 0) {
  54.       var href = window.location.href.split(/\?|#/)[0];
  55.       url = href.substring(0, href.lastIndexOf('/') + 1) + url;
  56.     }
  57.  
  58.     // Force no empty options.
  59.     if (typeof options != 'object')
  60.       options = {};
  61.  
  62.     if (!('focus' in options)) {
  63.         options.focus = false;
  64.     }
  65.     // Create new shell and get it's routing id.
  66.     var id = nw.allocateId();
  67.     options.object_id = id;
  68.     options.nw_win_id = id;
  69.     var routing_id = nw.createShell(url, options);
  70.  
  71.     return new global.Window(routing_id, true, id);
  72.   },
  73.   canSetVisibleOnAllWorkspaces: function() {
  74.     return canSetVisibleOnAllWorkspaces;
  75.   }
  76. };
  77.